{{template "header.html" .}}
<div id="form-result-message">
    <div class="message success hide">分类已更新</div>
    <div class="message error hide">分类更新失败：<span></span></div>
</div>
<form id="category-add-form" class="container form" action="/admin/categories/edit/{{.Category.id}}/" method="post">
    <div id="category-form-header">
        <h1 class="h1">编辑分类 "{{.Category.title}}"</h1>
    </div>
    <div id="category-form-main">
        <p class="item">
            <label for="category-add-name">名称</label>
            <input id="category-add-name" class="ipt" type="text" name="title" required="required"
                   value="{{.Category.title}}"/>
        </p>
        <p class="item">
            <label for="category-add-slug">缩略名</label>
            <input id="category-add-slug" class="ipt" type="text" name="slug" required="required"
                   value="{{.Category.slug}}"/>
        </p>
        <p class="item clear">
            <label for="category-add-desc" class="left">描述</label>
            <textarea class="ipt left" name="desc" id="category-add-desc">{{.Category.desc}}</textarea>
        </p>
        <p class="item submit">
            <button class="btn save" id="category-add-submit" type="submit">更新</button>
            <button class="btn delete" type="button" id="category-delete-submit">删除</button>
            <input type="hidden" id="category-delete-id" value="{{.Category.id}}"/>
        </p>
    </div>
</form>
<script type="text/javascript">
    $(document).ready(function () {
        ajaxForm("#category-add-form");
        $('#category-delete-submit').on("click", function (e) {
            e.preventDefault();
            if(!confirm("真的要删除？")){
                return;
            }
            var id = $('#category-delete-id').val();
            ajaxRequest("#category-add-form", "/admin/categories/delete/" + id + "/", "delete", "",function(json){
                if(json.res){
                   setTimeout(function(){
                       window.location.href = "/admin/categories/";
                   },1000);
                }
            });
        });
    });
</script>
</body>
</html>